package com.nurese.service;

import com.github.pagehelper.PageHelper;
import com.nurese.dao.PatientDao;
import com.nurese.dao.PatientDao;
import com.nurese.entity.Patient;
import com.nurese.entity.Patient;
import com.nurese.utils.BeanMapUtils;
import com.nurese.utils.MapParameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PatientService {
    @Autowired
    private PatientDao patientDao;

    public int create(Patient patient){
        System.out.println("++++3:"+BeanMapUtils.beanToMap(patient));
        return patientDao.create(patient);
    }
    public int delete(Integer id){
//        Map<String,Object> map=new HashMap<>();
//        map.put("id",id);
//        return patientDao.delete(map);

        return patientDao.delete(MapParameter.getInstance().add("id",id).getMap());
    }

    public int delete(String ids){

        String[] arr=ids.split(",");
        int flag=0;
        for (String s:arr){
            flag=patientDao.delete(MapParameter.getInstance().addId(Integer.parseInt(s)).getMap());
        }
        return flag;
    }
    public int update(Patient patient){
//        Map<String,Object> map= BeanMapUtils.beanToMapForUpdate(patient);
//        return patientDao.update(map);

        return patientDao.update(MapParameter.getInstance()
                .add(BeanMapUtils.beanToMapForUpdate(patient))
                .addId(patient.getId()).getMap());
    }
    public List<Patient> query(Patient patient){
        System.out.println("++++1:"+BeanMapUtils.beanToMap(patient));
        if (patient !=null && patient.getPage() !=null){
            PageHelper.startPage(patient.getPage(),patient.getLimit());
        }
        return patientDao.query(BeanMapUtils.beanToMap(patient));
    }
    public int count(Patient patient){
        return patientDao.count(BeanMapUtils.beanToMap(patient));
    }
    public Patient detail(Integer id){
        return patientDao.detail(MapParameter.getInstance().add("id",id).getMap());
    }
}